package tech.aistar.service.impl;

import org.apache.ibatis.session.SqlSession;
import tech.aistar.mapper.CommentMapper;
import tech.aistar.mapper.ReplyMapper;
import tech.aistar.service.ICommentService;
import tech.aistar.util.MybatisUtil;
import tech.aistar.vo.CommentVo;
import tech.aistar.vo.ReplyVo;

import java.util.List;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:
 * @date 2019/9/15 0015
 */
public class CommentServiceImpl implements ICommentService{



    @Override
    public List<CommentVo> findAllByPhoneId(Integer phoneId) {
        SqlSession sqlSession = MybatisUtil.getSqlSession();
        CommentMapper commentMapper = sqlSession.getMapper(CommentMapper.class);
        ReplyMapper replyMapper = sqlSession.getMapper(ReplyMapper.class);

        List<CommentVo> comments = commentMapper.findByPhoneId(phoneId);
        
        if(null!=comments && comments.size()>0){
            for (CommentVo c : comments) {
                List<ReplyVo> replyList = replyMapper.findByCommentId(c.getId());
                if(null!=replyList && replyList.size()>0){
                    c.setReplyVoList(replyList);
                }
            }
        }
        

        return comments;
    }
}
